﻿var deals = new Array();

$(function () {

	/* TODO: uncomment when we're ready for facebook */

	  var h = $("#hidJustBought");

	  if (h.length > 0) {
		deals.length = 0;
		var xmlDoc = $.parseXML(h.html());
		var $xml = $(xmlDoc);

		$xml.find('record').each(function () {
			var company = $(this).find('field[name=name]').attr('value');
			var city = $(this).find('field[name=city]').attr('value');

			var deal = 'Via gollie heb ik zojuist een superdeal gesloten met ' + company + ' in ' + city + '!';
			deals.push(deal);
		});
		
		InitFB();
	  }
	  

});

function OnFBInit() {
	if (deals.length > 0) {
		GetFbLoginStatus();

		window.setTimeout(function () {
			if (fbLoginStatus === 'connected')
				PostDeals();
			else if (fbLoginStatus === 'not_authorized')
				$('#dialog-posttofb').dialog('open');
		}, 500);
	}
}

function PostDeals() {
	fbPost(deals);
}